package com.openstack.javasdk;

import com.alibaba.fastjson.JSONObject;
import org.openstack4j.api.Builders;
import org.openstack4j.api.OSClient.OSClientV3;
import org.openstack4j.model.common.ActionResponse;
import org.openstack4j.model.storage.block.Volume;
import org.openstack4j.model.storage.block.VolumeSnapshot;
import org.openstack4j.model.storage.block.VolumeType;
import org.openstack4j.model.storage.object.SwiftAccount;
import org.openstack4j.model.storage.object.SwiftContainer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/swift")
public class SwiftModule {

    @GetMapping("/account")
    public String imageTypeList() {
        OSClientV3 os = Auth.getOS();
        SwiftAccount account = os.objectStorage().account().get();
        return JSONObject.toJSONString(account);
    }

    @GetMapping("/container/list")
    public String containerList() {
        OSClientV3 os = Auth.getOS();
        List<? extends SwiftContainer> containers = os.objectStorage().containers().list();
        return JSONObject.toJSONString(containers);
    }

//    {
//code: 404
//fault: "Not Found"
//success: false
//}
    @GetMapping("/container/create")
    public String containerCreate() {
        OSClientV3 os = Auth.getOS();
        ActionResponse response = os.objectStorage().containers().create("myContainerName");
        return JSONObject.toJSONString(response);
    }
}

